/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.core.wicket.panel.container;

import com.eelpo.cmmp.core.wicket.panel.grid.DataGrid;
import com.eelpo.cmmp.core.wicket.panel.navigator.AjaxPagingNavigator;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.AbstractPageableView;
import org.apache.wicket.model.Model;

/**
 * <pre>
 * 
 * 搜索列表容器
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public abstract class SearchListContainer<T> extends Panel {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 6694203105252516198L;

	public SearchListContainer(String id, String title, int pageSize) {

		super(id, new Model<String>(title));

		// 表单
		Form<T> form = renderForm("form");

		// 标题
		form.add(renderTitleLabel("title"));

		// 搜索
		form.add(renderSearchPanel("searchPanel"));

		// 数据列表
		
		DataGrid<T> dataGrid = renderDataGrid("dataGrid", pageSize);
		WebMarkupContainer container = new WebMarkupContainer("dateGridContainer");
		container.setOutputMarkupId(true);
		container.add(dataGrid);
		
		// 分页导航
		form.add(renderPagingNavigator("pageNavigator", container, dataGrid.getDataView()));
		form.add(container);

		add(form);
	}

	public Form<T> renderForm(String id) {
		return new Form<T>(id);
	}

	public Label renderTitleLabel(final String id) {
		return new Label(id, getDefaultModelObjectAsString());
	}

	public abstract Panel renderSearchPanel(final String id);

	public abstract DataGrid<T> renderDataGrid(final String id, int pageSize);

	public Panel renderPagingNavigator(final String id, final WebMarkupContainer parent, final AbstractPageableView<T> pageable) {
		return new AjaxPagingNavigator<T>(id, pageable, parent);
	}

}
